<template>
  <view class="module-item" :class="{ 'active': active }">
    <view class="handle">
      <u-icon name="list" color="#999" size="24"></u-icon>
    </view>
    <view class="content">{{ name }}</view>
    <view class="action" @click.stop="toggleActive">
      <u-icon v-if="active" name="minus-circle" color="#ff5722" size="24"></u-icon>
      <u-icon v-else name="plus-circle" color="#5ac725" size="24"></u-icon>
    </view>
  </view>
</template>

<script setup>
const props = defineProps({
  id: {
    type: String,
    required: true
  },
  name: {
    type: String,
    required: true
  },
  active: {
    type: Boolean,
    default: false
  },
  removable: {
    type: Boolean,
    default: true
  }
})

const emit = defineEmits(['update:active'])

const toggleActive = () => {
  if (!props.removable && props.active) {
    // 不可移除的必选模块
    uni.showToast({
      title: '此模块为必选模块，不可移除',
      icon: 'none'
    })
    return
  }
  
  emit('update:active', !props.active)
}
</script>

<style lang="scss" scoped>
.module-item {
  display: flex;
  align-items: center;
  background-color: #FFFFFF;
  border-radius: 8px;
  padding: 16px;
  margin-bottom: 12px;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.05);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  
  &.active {
    border-left: 4px solid #5ac725;
  }
  
  .handle {
    margin-right: 12px;
    display: flex;
    align-items: center;
    cursor: grab;
    
    /* 自定义拖动图标样式 */
    &::before {
      content: '';
      display: inline-block;
      width: 12px;
      height: 18px;
      background-image: radial-gradient(circle, #999 1.5px, transparent 1.5px);
      background-size: 6px 6px;
      background-position: 0 0;
      opacity: 0.7;
      margin-right: 5px;
    }
  }
  
  .content {
    flex: 1;
    font-size: 16px;
    color: #333;
  }
  
  .action {
    padding: 4px;
  }
  
  /* 拖动状态 */
  &:active {
    cursor: grabbing;
    transform: scale(1.02);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  }
}
</style> 